package com.lixw.langchain.handler;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.lixw.langchain.service.WeatherService;
import dev.langchain4j.agent.tool.P;
import dev.langchain4j.agent.tool.Tool;
import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName: InvoiceHandler
 * @Description:
 * @Author: xuweiLi
 * @Create: 2025/8/25 10:03
 **/
@Slf4j
public class InvoiceHandler {

    @Tool(value = "根据用户提交的开票信息进行开票", name = "开具发票助手")
    public String handle(
            @P(value = "公司名称", required = true) String companyName,
            @P(value = "税号", required = true) String dutyNumber,
            @P(value = "金额保留两位有效数字", required = true) String amount
    ) throws Exception {
        log.info("companyName =>>>> {} dutyNumber =>>>> {} amount =>>>> {}", companyName, dutyNumber, amount);

        return "开票成功！";
    }

    @Tool(value = "可以根据用户给的城市id查询天气", name = "天气查询工具")
    public JsonNode handle(
            @P(value = "城市id", required = true) String cityId
    ) throws Exception {
        JsonNode jsonNode = new WeatherService().getWeatherV7(cityId);
       /* try {
            jsonNode = new WeatherService().getWeatherV7("101010100");
        } catch (Exception e) {
            log.error(e.getMessage());
        }*/
        log.info("天气查询结果: {}", jsonNode);

        return jsonNode;
    }

}